package top.wshape1.easyscan.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import top.wshape1.easyscan.constraint.PackageEnum;

/**
 * @author Wshape1
 * @version 1.0
 * @description
 * @since 2023-05-18
 */
public class CodeStringUtil {


    public static PackageEnum resolveQrString(String s) {
        PackageEnum type = null;

        String lowerCase = s.toLowerCase(Locale.ROOT);

        if (lowerCase.contains("weixin.qq.com") || lowerCase.startsWith("wxp") || lowerCase.startsWith("https://app.zgzys.cn/open/m")) {
            // 微信登录
            type = PackageEnum.WECHAT;
        } else if (lowerCase.contains("qq")) {
            // qq登录
            type = PackageEnum.QQ;
        } else if (lowerCase.contains("passport2.chaoxing.com") || lowerCase.contains("mobilelearn.chaoxing.com")) {
            // 学习通登录
            type = PackageEnum.CHAOXING;
        } else if (lowerCase.contains("account.aliyun.com/login")) {
            // 支付宝登录
            type = PackageEnum.ALIPAY;
        } else if (checkUrl(lowerCase)) {
            type = PackageEnum.URL;
        }
        return type;
    }

    private static boolean checkUrl(String s) {
        String[] prefix = new String[]{"http:", "https:", "mqq:", "mqqapi:", "smsto:", "mailto:", "ftp:"};

        for (String pre : prefix) {
            if (s.startsWith(pre)) {
                return true;
            }
        }
        return false;
    }

}
